import wmi
import winreg

# 网卡名称
adapter_name = "以太网"

# 获取所有网卡信息
c = wmi.WMI()
wmi_adapters = c.Win32_NetworkAdapter()
adapter = None

# 查找对应的网卡信息
for wmi_adapter in wmi_adapters:
    if wmi_adapter.NetConnectionID == adapter_name:
        adapter = wmi_adapter
        break

if adapter is None:
    print(f"找不到名称为 {adapter_name} 的网卡")
else:
    # 获取网卡的MAC地址
    mac_address = adapter.MACAddress
    print(f"网卡 {adapter_name} 的MAC地址为 {mac_address}")

    # 获取网卡对应的注册表位置
    reg_path = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}"
    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path) as reg_key:
        for i in range(10000):
            try:
                sub_key_name = winreg.EnumKey(reg_key, i)
                with winreg.OpenKey(reg_key, sub_key_name) as sub_key:
                    if winreg.QueryValueEx(sub_key, "NetCfgInstanceId")[0] == adapter.GUID:
                        adapter_key = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}\\" + sub_key_name
                        print(f"网卡 {adapter_name} 对应的注册表位置为 {adapter_key}")
                        break
            except OSError:
                break
